package alik.notes.server;


import java.util.List;

import alik.notes.server.persistence.NotesPersistence;
import alik.notes.shared.data.Note;
import alik.notes.shared.service.NotesService;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
public class NotesServiceImpl extends RemoteServiceServlet implements
		NotesService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9129964825493119441L;

	public List<Note> getNotes() {
		String userId = "Anonymous";
	    UserService userService = UserServiceFactory.getUserService();
	    User user = userService.getCurrentUser();
	    if (user != null) {
	    	userId = user.getUserId();
	    }
		
	    List<Note> notes = NotesPersistence.queryNotes(userId);
	    return notes;
	}

	@Override
	public void addNote(Note note) {
		NotesPersistence.addNote(note);
	}

}
